<?php
namespace jy_shopweixiu;
defined('BY_JYA') or exit('error');
/*
	订单
*/
class order extends \plugin{
	//订单创建时，执行此方法，执行相关操作
	public $sendtypes=array(
		'1'=>'上门服务',
		'2'=>'到店服务',
		'3'=>'虚拟商品',
	);
	public function get_order($order_id,$merchid=0){
		if($this->order && $this->order['id']==$order_id){
			return $this->order;
		}
		$this->order=pdo_get('jy_weishop_order',array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		if($merchid){
			$this->order['goods']=pdo_getall('jy_weishop_order_goods',array('orderid'=>$order_id,'merchid'=>$merchid));
		}else{
			$this->order['goods']=pdo_getall('jy_weishop_order_goods',array('orderid'=>$order_id));
		}
		foreach($this->order['goods'] as &$goods){
			$goods_data=pdo_get('jy_weishop_goods',array('id'=>$goods['goodsid']),array('title','image','type','fang_credit2','isverify','goodssn','productsn','noticemid','totalcnf','noticetype'));
			//商品规格
			if($goods['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$goods['optionid']),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
				}
				$goods['selespename']=implode("，",$specs);
			}
			$goods=array_merge($goods,$goods_data);
		}
		return $this->order;
	}
	//接单
	public function order_send($order_id,$params=array(),$isup=false){
		$this->get_order($order_id);
		if($this->order['status']==2 || ($this->order['send_status']==$params['send_status'] && $params['send_status'])){
			if(!$isup){
				exi('不能接单，该订单已接单！','error');
			}
		}
		if($params['send_status']){
			pdo_update('jy_weishop_order',array('status'=>15,'sendtime'=>time(),'send_status'=>$params['send_status']),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		}else{
			pdo_update('jy_weishop_order',array('status'=>15,'sendtime'=>time(),'send_status'=>12),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
			pdo_update('jy_weishop_order_goods',array('status'=>15,'sendtime'=>time()),array('orderid'=>$order_id));
			$this->order['sendtime']=TIMESTAMP;
			model('jy_shifu/notice')->notice_send2buyer($this->order);
		}
		return true;
	}
}